<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="600"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form :model="form" :rules="rules" ref="dialogForm" label-width="80px">
      <el-tabs type="border-card">
        <el-tab-pane ref="tab" label="基础信息">
          <el-row justify="space-evenly">
            <el-col :span="24">
              <el-descriptions title="" :column="2" border label-align="right">
                <el-descriptions-item>
                  <template #label>单据日期</template>
                  {{ form.created_at }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>单号</template>
                  {{ form.main.code }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>规格</template>
                  {{ form.material.spec }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>品名</template>
                  {{ form.material.name }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>颜色</template>
                  {{ form.color }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>缸号</template>
                  {{ form.dyelot }}
                </el-descriptions-item>

                <el-descriptions-item>
                  <template #label>开卡匹</template>
                  {{ form.auxiliary_quantity }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template #label>开卡数</template>
                  {{ form.quantity }}
                </el-descriptions-item>
                <el-descriptions-item label="倒卷" label-class-name="light-blue">
                  <el-input v-model="form.roll_quantity" style="width: 200px">
                    <template #prepend>
                      <el-input
                        v-model="form.roll_auxiliary_quantity"
                        style="width: 70px"
                      />
                    </template>
                  </el-input>
                </el-descriptions-item>

                <el-descriptions-item>
                  <template #label>倒卷备注</template>
                  <el-input v-model="form.remark"> </el-input>
                </el-descriptions-item>
              </el-descriptions>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()" v-if="!showonly"
        >保 存</el-button
      >
    </template>
  </el-dialog>
</template>
<script>
import tool from "@/utils/tool";
export default {
  emits: ["success", "closed"],
  components: {},
  data() {
    return {
      mode: "add",
      form: {
        material: {},
        main: {},
      },

      titleMap: {
        add: "新增",
        edit: "编辑",
      },
      rules: {},
      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.pro.OpenCard.saveroll.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", res);
            this.$message.success("操作成功");
          }
        }
      });
    },

    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, tool.removeNull(data));
      return this;
    },
  },
};
</script>
